$(".del").click(function() {
	var json = {
		"broadcastId" : $("#broadcastId").val(),
		"musicId" : $(this).next().val()
	};
	$.post("/Dein/broadcast/deleteBroadcastMusic", json, function(data) {
		var json = eval("(" + data + ")");
		alert(json.result);
//		if (json.result == "true") {
//			alert(json.result);
//		}
	});
});

//admin_newBroadcast.jsp
var musicIds=new Array();
var musicIdsCopy;

$("#add").click(function() {
	$(".musicList").show();
	$.ajax({
		type:"post",
		url:"/Dein/music/getMusicList",
		success:function(data){
			var b;
			$.each(data,function(index,v){
				b=true;
				$.each(musicIds,function(){
					if(v.musicId==this){
						b=false;
						$("<li></li>").attr("id",v.musicId).text(v.singer+" - "+v.musicName).css("background-color","#F0FFFF").appendTo("ul");
						return false;
					}
				});
				if(b==true){
					$("<li></li>").attr("id",v.musicId).text(v.singer+" - "+v.musicName).appendTo("ul");
				}
			});
		},
		complete:function(){
			musicIdsCopy=musicIds.slice(0);
			musicIds=[];
		}
	});
});

$("ul>li").live("click",function(){
	if($(this).css("background-color")=="rgb(255, 255, 255)"){
		$(this).css("background-color","#F0FFFF");
	}else{
		$(this).css("background-color","white");
	}
});

$("#confirm").click(function(){
	var i=0;
	musicIds=new Array();
	$("ul>li").each(function(){
		if($(this).css("background-color")=="rgb(240, 255, 255)"){
			musicIds[i++]=$(this).attr("id");
		}
	});
	$(".musicList").hide();
	$("ul").empty();
});

$("#close").click(function(){
	musicIds=musicIdsCopy.slice(0);
	$(".musicList").hide();
	$("ul").empty();
});

$("#broadcastName").blur(function(){
	
});

$("#complete").click(function(){
//	if($("#broadcastName").val()==""){
//		alert("请输 入电台的名字");
//	}
//	var json={broadcastName:$("#broadcastName").val()};
//	$.post("/Dein/broadcast/broadcastExist",json,function(data){
//		var result=eval("("+data+")");
//		if(result.result=="true"){
//			alert("电台的名字已存在");
//		}else{
//			var jsonData={
//					broadcastName:$("#broadcastName").val(),
//					musicIds:musicIds
//					};
//			$.post("/Dein/broadcast/createBroadcast",jsonData,function(){
//				alert("success");
//			});
//		}
//	});
	var jsonData={
			broadcastName:$("#broadcastName").val(),
			musicIds:musicIds
			};
$.post("broadcast/createBroadcast",jsonData,function(data){
	alert("ok");
});
//	alert($("#broadcastName").val());
});